package 面试2025.京东;

public class 最大子序和 {
    /**
     * 给定一个int数组，返回这个数据的连续子数组之和最大值
     */

    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,82,61,71,81};
        int maxSum = getMaxSum(arr);
        System.out.println(maxSum);
    }
    private static int getMaxSum(int[] nums){
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int res = dp[0];
        for(int i = 1;i < nums.length;i++){
            if(nums[i] > nums[i - 1]){
                dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
            }
            res = Math.max(res, dp[i]);
        }
        return res;
    }
}
